package com.site.util;

import java.util.Random;

/**
 * 产生随机数机器
 * @author zhouq
 *
 */
public class RandMachine {
	/**
	 * 根据长度产生随机数
	 * @param length	需要随机数的长度
	 * @return
	 */
	public static String createRandStr(int randLength){
		StringBuffer randBuf = new StringBuffer();
	 	int n = 10;
        Random rand = new Random();
        boolean[] bool = new boolean[n];
        int num =0;
        for (int i = 0; i<randLength; i++){
            do{
                //如果产生的数相同继续循环
                num = rand.nextInt(n);    
            }while(bool[num]);
            bool[num] =true;
            
            randBuf.append(num);
        }
	    return randBuf.toString();
	}
	
/*	public static void main(String[] args) {
		String str = null;
		for(int i=0;i<10;i++){
			str = createRandStr(8);
			System.out.println(str);
		}
	}*/
}
